<% content_for :form_scripts do %>
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
  jQuery('.select2').select2({width:'element'});
});
</script>
<% end %>

<!-- Source Form -->
<%= form_for(@location,:html => {:id=>"editsource"}) do |f| %>
  <!-- Errors -->
  <% if @location.errors.any? %>
    <div id="error_explanation">
      <strong><%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:</strong>
        <ul>
      <% @location.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <%= f.hidden_field :id %>
  
  <!-- Type -->
  <div class="field" id="types">
    *<%= f.label :type %><br />
    <span class="subtext">What'd you find? Be as specific as possible. Suggest a new plant name if you can't find yours in the list.</span><br>
      <% @location.locations_types.each{ |lt|  %>
      <%= f.fields_for :locations_types, lt, :index => "update_#{lt.id}" do |f2| %>
        <div class="type">
        <%= f2.select(:type_id,Type.order("name").collect{ |t| [t.name,t.id] },{:include_blank => true},{:class=>"select2"}) %> or
        <%= f2.text_field :type_other, :size => 15 %>
        <%= link_to_function "[X]", "$(this).up('.type').remove()" %><br>
        </div>
      <% end %>
    <% } %>
    <% if @current_action == "new" or @current_action == "create" %>
    <%= f.fields_for :locations_types, :index => "new_0" do |f2| %>
      <div class="type">
      <%= f2.select(:type_id,Type.order("name").collect{ |t| [t.name,t.id] },{:include_blank => true},{:class=>"select2"}) %> or
      <%= f2.text_field :type_other, :size => 15 %>
      <%= link_to_function "[X]", "$(this).up('.type').remove()" %><br>
      </div>
    <% end %>
    <% end %>
  </div>
  <%= add_locations_type_link "+ Add another", f %>
  
  <!-- Location -->
  <div class="field">
    <!--*<%= f.label :address %><br />-->
    *<label for="location_address">Location</label><br>
    <span class="subtext">Determined from your current location (when available) or a marker you placed. Adjust the location by moving the map marker.</span><br>
    Lat-Lon <%= f.text_field :lat, :size => 12, :value => @lat %>, <%= f.text_field :lng, :size => 12, :value => @lng %><br>
    
    <!-- Address (if new) -->
    <% if @current_action == "new" or @current_action == "create" %>
      <div style="margin-top: 0.25em;">Address <span class="subtext-inline">will <i>overwrite</i> the displayed location, so don't provide one if you want to use Lat-Lon.</span></div>
      <%= f.text_area :address, :size => "40x2" %><br>
      <a href="#" onclick="update_marker();">>> Update map from address</a>
    <% end %>
  </div>
  
  <!-- Author (if new or admin) -->
  <% if @current_action == "new" or @current_action == "create" or (@current_action == "edit" and !current_admin.nil?) %>
  <div class="field">
    <%= f.label :Author %><br />
    <span class="subtext">Displayed on map. Leave blank if you prefer to remain anonymous.</span><br>
    <%= f.text_field :author, :size => 40 %>
    <span>
  </div>
  <% end %>

  <!-- Description -->
  <div class="field">
    <!--<%= f.label :description_and_notes %><br />-->
    <label for="location_description_and_notes">Description</label><br>
    <span class="subtext">Location details, access issues, plant health...</span><br>
    <%= f.text_area :description, :size => "50x10" %>
  </div>
  
  <!-- Season -->
  <div class="field">
    <%= f.label :season %><br />
    <span class="subtext">When can the source be harvested? Leave blank if you don't know.</span><br>
    <%= f.select(:season_start,Location::Months.collect{ |m| [m,Location::Months.index(m)] },:include_blank => true) %> to 
    <%= f.select(:season_stop,Location::Months.collect{ |m| [m,Location::Months.index(m)] },:include_blank => true) %>, or
    <%= f.check_box(:no_season) %> No Season
  </div>
  
  <!-- Unverified -->
  <div class="field">
    <label>Unverified</label> <%= f.check_box(:unverified) %><br>
    <span class="subtext">If you haven't actually seen this source, or are unsure of its identity.</span>
  </div>
  
  <!-- Quality Rating -->
  <div class="field">
    <%= f.label :quality_rating %><br />
    <span class="subtext">Rate the tastiness of this source.</span><br>
    <%= f.select(:quality_rating,Location::Ratings.collect{ |r| [r,Location::Ratings.index(r)] },:include_blank => true) %>
  </div>
  
  <!-- Yield Rating -->
  <div class="field">
    <%= f.label :yield_rating %><br />
    <span class="subtext">Rate the productivity of this source.</span><br>
    <%= f.select(:yield_rating,Location::Ratings.collect{ |r| [r,Location::Ratings.index(r)] },:include_blank => true) %>
  </div>
  
  <!-- Access -->
  <div class="field">
    <%= f.label :access %><br />
    <span class="subtext">Access status of this source. Leave blank if you don't know.</span><br>
    <%= f.select(:access,Location::AccessModes.collect{ |r| [r,Location::AccessModes.index(r)] },:include_blank => true) %>
  </div>

  <br>
  <!-- Captcha -->
  <% if current_admin.nil? %>
  	<br>
	<% end %>
  <div id="captcha">
  <%= recaptcha_tags(:display => {:theme => 'white'}) if current_admin.nil? %>
  </div>
  
  <br>
  <!-- Submit -->
  <div class="actions">
    <%= f.submit "Submit" %>
    <% if @current_action == "new" %>
    <%= check_box_tag(:create_another, '1', false) %> Create another<br>
    <% end %>
  </div>
  
<% end %>
</form>
